<?php
namespace yan\xss_sql_filter\validator;
use Yii;
use yan\xss_sql_filter\utils\MyValidator;
class NormalNameValidator extends \yii\validators\Validator{

    public function init(){
        parent::init();
        if ($this->message === null) {
            $this->message = Yii::t('yii', '{attribute} Error Value');
        }
    }
    public function validateAttribute($model, $attribute){
        $value = $model->$attribute;
        if (!$this->validateName($value)) {            
            $this->addError($model, $attribute, $this->message);
        }
    }
    public function validateValue($value){
        if(!$this->validateName($value)){
            return [$this->message, []];
        }
        return null;
    }
    public function validateName($values){
        return MyValidator::isNornalName($values);
    }
}